const app = getApp();
Page({
  data: {
    detail: {},
    specType: 1,
  },
  onLoad: function (options) {
    let that = this;
    that.getInfo(options.id);
  },
  getInfo(id){
    let that = this;
    let order_id = id;
    wx.showLoading({
      title: '加载中...',
    })
    app.request('order/orderDetail',{ order_id },'GET',false,function(res){
      that.setData({
        pageShow: true,
        detail: res.data.data,
      })
    })
  },
  onShow: function () {

  },
  copyText(e){
    let that = this;
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success(res){
        wx.showToast({
          title: '复制成功',
        })
      }
    })
  },
  orderHandle(e){
    let that = this;
    let type = e.currentTarget.dataset.type;
    let order_id = that.data.detail.id;
    switch (type){
      case "cancel":
        wx.showModal({
          content: '确认取消该订单',
          success(res) {
            if (res.confirm) {
              app.request('order/cancelOrder', { order_id }, 'GET', false, function (res) {
                wx.showToast({
                  title: '取消成功',
                  mask: true,
                });
                setTimeout(function () {
                  wx.navigateBack({
                    delta: 1,
                  })
                }, 2000)
              })
            }
          }
        })
        break;
      case "pay":
        app.request('pay/payOrder', { order_id }, 'GET', false, function (res) {
          wx.requestPayment({
            'timeStamp': res.data.data.timeStamp,
            'nonceStr': res.data.data.nonceStr,
            'package': res.data.data.package,
            'signType': res.data.data.signType,
            'paySign': res.data.data.paySign,
            success: function (res) {
              wx.showToast({
                title: '支付成功',
                mask: true,
              });
              setTimeout(function () {
                wx.navigateBack({
                  delta: 1,
                })
              }, 2000)
            },
          });
        })
        break;
      case "service":
        wx.navigateTo({
          url: '/pages/order/orderRefund/orderRefund?id=' + order_id,
        })
        break;
      case "refund":
        wx.navigateTo({
          url: '/pages/order/orderRefund/orderRefund?id=' + order_id + '&type=1',
        })
        break
      case "receipt":
        wx.showModal({
          content: '确认收货',
          success(res) {
            if (res.confirm) {
              app.request('order/receiveOrder', { order_id }, 'GET', false, function (res) {
                wx.showToast({
                  title: '确认成功',
                  mask: true,
                });
                setTimeout(function () {
                  wx.navigateBack({
                    delta: 1,
                  })
                }, 2000)
              })
            }
          }
        })
        break;
    }
  },
  onShareAppMessage: function(){
    return {
      path: '/pages/index/index'
    }
  }

})